package com.ingenieria.industrial.service.implementacion;

import com.ingenieria.industrial.dao.implementacion.EventoDAO;
import com.ingenieria.industrial.dto.Evento;
import com.ingenieria.industrial.service.diseño.IEventoService;
import java.sql.SQLException;
import java.util.ArrayList;

public class EventoService extends BaseSimpleService implements IEventoService {

    private EventoDAO dao;

    @Override
    public int insert(Evento evento) throws Exception {
        int results = -1;
        try {
            begin();
            results = dao.insert(evento);
            commit();
        } catch (Exception sos) {
            throw handleError(sos);
        } finally {
            handleRelease();
        }
        return results;
    }

    @Override
    public int update(Evento evento) throws Exception {
        int results = -1;
        try {
            begin();
            results = dao.update(evento);
            commit();
        } catch (Exception sos) {
            throw handleError(sos);
        } finally {
            handleRelease();
        }
        return results;
    }

    @Override
    public int delete(String cod_proc) throws Exception {
        int results = -1;
        try {
            begin();
            results = dao.delete(cod_proc);
            commit();
        } catch (Exception sos) {
            throw handleError(sos);
        } finally {
            handleRelease();
        }
        return results;
    }

    @Override
    public ArrayList<Evento> getAll() throws Exception {
        try {
            begin();
            return dao.getAll();
        } catch (Exception sos) {
            throw handleError(sos);
        } finally {
            handleRelease();
        }
    }

    @Override
    public Evento getById(String cod_eve) throws Exception {
        try {
            begin();
            return dao.getById(cod_eve);
        } catch (Exception sos) {
            throw handleError(sos);
        } finally {
            handleRelease();
        }
    }

    @Override
    protected void initDAO() throws SQLException {
        dao = new EventoDAO(transact);
    }

}
